﻿using System;
using System.IO;

namespace Microsoft.WowAddonStudio.FrameXml.Design.Serialization
{
	/// <summary>
	/// 
	/// </summary>
    public class FileFrameXmlSerializer : FrameXmlSerializer
    {
        private readonly string frameXmlPath;

        /// <summary>
        /// Initializes a new instance of the <see cref="FileFrameXmlSerializer"/> class.
        /// </summary>
        /// <param name="frameXmlPath">The frame XML path.</param>
        public FileFrameXmlSerializer(string frameXmlPath)
        {
            if (frameXmlPath == null)
                throw new ArgumentNullException("frameXmlPath");

            this.frameXmlPath = frameXmlPath;
        }

        /// <summary>
        /// Reads the FrameXML.
        /// </summary>
        /// <returns>
        /// A <see cref="String"/> containing the FrameXML.
        /// </returns>
        public override string ReadFrameXml()
        {
            return File.ReadAllText(frameXmlPath);
        }

        /// <summary>
        /// Writes the FrameXML.
        /// </summary>
        /// <param name="frameXml">A <see cref="String"/>containing the FrameXML.</param>
        public override void WriteFrameXml(string frameXml)
        {
            if (frameXml == null)
                throw new ArgumentNullException("frameXml");

			File.WriteAllText(frameXmlPath, frameXml);
        }
    }
}
